package com.hailiang.saas.auth.filter;

import com.hailiang.saas.auth.common.Constant;
import com.hailiang.saas.auth.config.AuthenticationConfig;
import com.hailiang.saas.auth.logout.LogoutSuccessHandler;
import com.hailiang.saas.auth.logout.PasswordLogoutHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

/**
 * 登出过滤器:/sso/channel/logout/auth
 * @author : pangfuzhong
 * @description
 * @date : 2021/9/29 14:01
 */
@Slf4j
public class UnifiedLogoutFilter extends LogoutFilter {
    private AuthenticationConfig authenticationConfig;
    public UnifiedLogoutFilter(AuthenticationConfig authenticationConfig) {
        super(new LogoutSuccessHandler(authenticationConfig), new PasswordLogoutHandler(authenticationConfig));
        this.authenticationConfig = authenticationConfig;
        this.setLogoutRequestMatcher(new AntPathRequestMatcher(this.authenticationConfig.getLogoutAuthUrl(), Constant.POST));
    }
}
